package agents;

import constants.*;

import interfaces.ActionInterface;
import interfaces.AgentInterface;
import interfaces.impl.Agent;
import interfaces.impl.actions.ActionMove;

import java.awt.Graphics;
import java.util.ArrayList;

import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionGenerateObject;

public class AgentUpdateCastle extends Agent implements AgentInterface {
	
	private ActionMove actionMove;
	private ActionGenerateObject generateCastle;
	
	
	public AgentUpdateCastle(){
		this.id = Constants.AGENT_UPDATE_CASTLE;
		
		
		listActions = new ArrayList<ActionInterface>();
		
		generateCastle=new ActionGenerateObject();
		listActions.add(generateCastle);
		
		actionMove = new ActionMove(priority+1);
		listActions.add(actionMove);
		
		
	}

	@Override
	public void update(WorldObject object, Universe worldI, double time) {
		/*if(!canUpdate(object)){
			System.out.println("Me falta alguna accion para poder actuar");
			return;
		}*/
	
		for(WorldObject obj : object.getListObjects()){
			if(obj.getObjectReference()==Constants.OBJECT_REFERENCE_MONEY){
				
				actionMove.setSource(object);
				actionMove.setTarget(obj);
				actionMove.setX(object.getPosition().getX()-20);
				actionMove.setY(object.getPosition().getY()-70);
				obj.setImmediatlyActionToDo(actionMove);
				
			}
		}
		
		for(SpetialFeature fe : object.getListFeatures()){
			if(fe.getId()==Constants.SPETIAL_FEATURE_CURRENT_LIFE){
				if(fe.getValue()<=0){
					if(object.getObjectReference()==Constants.OBJECT_REFERENCE_CASTLE_BLUE){
						generateCastle.setObjectReference(Constants.OBJECT_REFERENCE_CASTLE_RED);
					}
					else{
						generateCastle.setObjectReference(Constants.OBJECT_REFERENCE_CASTLE_BLUE);
					}
					worldI.getListObjectsToKill().add(object);
					/*generateCastle.setTarget(object);
					generateCastle.setSource(object);
					generateCastle.setX(object.getPosition().getX());
					generateCastle.setY(object.getPosition().getY());
					for(WorldObject o : worldI.getListObjects()){
						if(o.getObjectReference()!=object.getObjectReference() && (o.getObjectReference()==Constants.OBJECT_REFERENCE_CASTLE_BLUE || o.getObjectReference()==Constants.OBJECT_REFERENCE_CASTLE_RED))
							generateCastle.setTarget(null);
							o.setImmediatlyActionToDo(generateCastle);
						
					}*/
				}
			}
		}
		
	}

	@Override
	public void paint(Graphics g, WorldObject object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setName(String name) {
		// TODO Auto-generated method stub
		
	}
	
	

}
